/*
 * Copyright (C) 2010-2011 Apple Inc. All rights reserved.
 *
 * This document is the property of Apple Inc.
 * It is considered confidential and proprietary.
 *
 * This document may not be reproduced or transmitted in any form,
 * in whole or in part, without the express written permission of
 * Apple Inc.
 */
#ifndef __PLATFORM_SOC_MIU_H
#define __PLATFORM_SOC_MIU_H

#include <lib/devicetree.h>
#include <platform/soc/hwregbase.h>

#define	rREMAP_CTL			(*(volatile u_int32_t *)(PIO_BASE_ADDR + 0x0000))

#define rCIM_TID_DEST_CONFIG(n)		(*(volatile u_int32_t *)(CIM_BASE_ADDR + 0x000 + (n) * 4))
#define rCIM_CONFIG_REG			(*(volatile u_int32_t *)(CIM_BASE_ADDR + 0x040)
#define rCIM_STATUS_REG0		(*(volatile u_int32_t *)(CIM_BASE_ADDR + 0x044)
#define rCIM_STATUS_REG1		(*(volatile u_int32_t *)(CIM_BASE_ADDR + 0x048)

#define  CDIO_IOP_RRLIMIT		(0x0000)
#define rCDIO_IOP_RRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_RRLIMIT))
#define  CDIO_IOP_WRLIMIT		(0x0004)
#define rCDIO_IOP_WRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_WRLIMIT))
#define  CDIO_IOP_RTLIMIT		(0x0008)
#define rCDIO_IOP_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_RTLIMIT))
#define  CDIO_IOP_WTLIMIT		(0x000C)
#define rCDIO_IOP_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_WTLIMIT))
#define  CDIO_IOP_WGATHER		(0x0010)
#define rCDIO_IOP_WGATHER		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_WGATHER))
#define  CDIO_IOP_C_REMAP_EN		(0x001C)
#define rCDIO_IOP_C_REMAP_EN		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_C_REMAP_EN))
#define  CDIO_IOP_RC_REMAP(n)		(0x0020 + ((n) * 4))
#define rCDIO_IOP_RC_REMAP(n)		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_RC_REMAP(n)))
#define  CDIO_IOP_WC_REMAP(n)		(0x0030 + ((n) * 4))
#define rCDIO_IOP_WC_REMAP(n)		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_IOP_WC_REMAP(n)))
#define  CDIO_CDMA_RRLIMIT		(0x1000)
#define rCDIO_CDMA_RRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CDMA_RRLIMIT))
#define  CDIO_CDMA_WRLIMIT		(0x1004)
#define rCDIO_CDMA_WRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CDMA_WRLIMIT))
#define  CDIO_CDMA_RTLIMIT		(0x1008)
#define rCDIO_CDMA_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CDMA_RTLIMIT))
#define  CDIO_CDMA_WTLIMIT		(0x100C)
#define rCDIO_CDMA_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CDMA_WTLIMIT))
#define  CDIO_CDMA_WGATHER		(0x1010)
#define rCDIO_CDMA_WGATHER		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CDMA_WGATHER))
#define  CDIO_UPERF_RRLIMIT		(0x2000)
#define rCDIO_UPERF_RRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_UPERF_RRLIMIT))
#define  CDIO_UPERF_WRLIMIT		(0x2004)
#define rCDIO_UPERF_WRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_UPERF_WRLIMIT))
#define  CDIO_UPERF_RTLIMIT		(0x2008)
#define rCDIO_UPERF_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_UPERF_RTLIMIT))
#define  CDIO_UPERF_WTLIMIT		(0x200C)
#define rCDIO_UPERF_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_UPERF_WTLIMIT))
#define  CDIO_UPERF_WGATHER		(0x2010)
#define rCDIO_UPERF_WGATHER		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_UPERF_WGATHER))
#define  CDIO_AUDIO_RRLIMIT		(0x3000)
#define rCDIO_AUDIO_RRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_AUDIO_RRLIMIT))
#define  CDIO_AUDIO_WRLIMIT		(0x3004)
#define rCDIO_AUDIO_WRLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_AUDIO_WRLIMIT))
#define  CDIO_AUDIO_RTLIMIT		(0x3008)
#define rCDIO_AUDIO_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_AUDIO_RTLIMIT))
#define  CDIO_AUDIO_WTLIMIT		(0x300C)
#define rCDIO_AUDIO_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_AUDIO_WTLIMIT))
#define  CDIO_AUDIO_WGATHER		(0x3010)
#define rCDIO_AUDIO_WGATHER		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_AUDIO_WGATHER))
#define  CDIO_PIO_RTLIMIT		(0x5008)
#define rCDIO_PIO_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_PIO_RTLIMIT))
#define  CDIO_PIO_WTLIMIT		(0x500C)
#define rCDIO_PIO_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_PIO_WTLIMIT))
#define  CDIO_CIM_RTLIMIT		(0x6008)
#define rCDIO_CIM_RTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CIM_RTLIMIT))
#define  CDIO_CIM_WTLIMIT		(0x600C)
#define rCDIO_CIM_WTLIMIT		(*(volatile u_int32_t *)(CDIO_WIDGETS_BASE_ADDR + CDIO_CIM_WTLIMIT))

#define  CDIO_AR_CHAN_ARB_MI0		(0x0408)
#define rCDIO_AR_CHAN_ARB_MI0		(*(volatile u_int32_t *)(CDIO_PL301_BASE_ADDR + CDIO_AR_CHAN_ARB_MI0))
#define  CDIO_AW_CHAN_ARB_MI0		(0x040C)
#define rCDIO_AW_CHAN_ARB_MI0		(*(volatile u_int32_t *)(CDIO_PL301_BASE_ADDR + CDIO_AW_CHAN_ARB_MI0))
#define  CDIO_AR_CHAN_ARB_MI1		(0x0428)
#define rCDIO_AR_CHAN_ARB_MI1		(*(volatile u_int32_t *)(CDIO_PL301_BASE_ADDR + CDIO_AR_CHAN_ARB_MI1))
#define  CDIO_AW_CHAN_ARB_MI1		(0x042C)
#define rCDIO_AW_CHAN_ARB_MI1		(*(volatile u_int32_t *)(CDIO_PL301_BASE_ADDR + CDIO_AW_CHAN_ARB_MI1))

#define  UPERF_OTG_QOS			(0x0014)
#define rUPERF_OTG_QOS			(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OTG_QOS))
#define  UPERF_OTG_CACHE		(0x0018)
#define rUPERF_OTG_CACHE		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OTG_CACHE))
#define  UPERF_EHCI_QOS			(0x0034)
#define rUPERF_EHCI_QOS			(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_EHCI_QOS))
#define  UPERF_EHCI_CACHE		(0x0038)
#define rUPERF_EHCI_CACHE		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_EHCI_CACHE))
#define  UPERF_OHCI0_QOS		(0x0054)
#define rUPERF_OHCI0_QOS		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OHCI0_QOS))
#define  UPERF_OHCI0_CACHE		(0x0058)
#define rUPERF_OHCI0_CACHE		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OHCI0_CACHE))
#define  UPERF_OHCI1_QOS		(0x0074)
#define rUPERF_OHCI1_QOS		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OHCI1_QOS))
#define  UPERF_OHCI1_CACHE		(0x0078)
#define rUPERF_OHCI1_CACHE		(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_OHCI1_CACHE))
#define  UPERF_RTLIMIT			(0x0088)
#define rUPERF_RTLIMIT			(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_RTLIMIT))
#define  UPERF_WTLIMIT			(0x008C)
#define rUPERF_WTLIMIT			(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_WTLIMIT))
#define  UPERF_USB2HOST1EHCI_QOS	(0x0094)
#define rUPERF_USB2HOST1EHCI_QOS	(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_USB2HOST1EHCI_QOS))
#define  UPERF_USB2HOST1EHCI_CACHE	(0x0098)
#define rUPERF_USB2HOST1EHCI_CACHE	(*(volatile u_int32_t *)(UPERF_WIDGETS_BASE_ADDR + UPERF_USB2HOST1EHCI_CACHE))

#define  UPERF_AR_CHAN_ARB_MI		(0x0408)
#define rUPERF_AR_CHAN_ARB_MI		(*(volatile u_int32_t *)(UPERF_PL301_BASE_ADDR + UPERF_AR_CHAN_ARB_MI0))
#define  UPERF_AW_CHAN_ARB_MI		(0x040C)
#define rUPERF_AW_CHAN_ARB_MI		(*(volatile u_int32_t *)(UPERF_PL301_BASE_ADDR + UPERF_AW_CHAN_ARB_MI0))

#define  HPERF_NRT_DART_DART_RTLIMIT	(0x0000)
#define rHPERF_NRT_DART_DART_RTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_DART_RTLIMIT))
#define  HPERF_NRT_DART_DART_WTLIMIT	(0x0004)
#define rHPERF_NRT_DART_DART_WTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_DART_WTLIMIT))
#define  HPERF_NRT_DART_DART_WGATHER	(0x0010)
#define rHPERF_NRT_DART_DART_WGATHER	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_DART_WGATHER))
#define  HPERF_NRT_DART_SCALER0_RTLIMIT	(0x0108)
#define rHPERF_NRT_DART_SCALER0_RTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_SCALER0_RTLIMIT))
#define  HPERF_NRT_DART_SCALER0_WTLIMIT	(0x010C)
#define rHPERF_NRT_DART_SCALER0_WTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_SCALER0_WTLIMIT))
#define  HPERF_NRT_DART_SCALER1_RTLIMIT	(0x0208)
#define rHPERF_NRT_DART_SCALER1_RTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_SCALER1_RTLIMIT))
#define  HPERF_NRT_DART_SCALER1_WTLIMIT	(0x020C)
#define rHPERF_NRT_DART_SCALER1_WTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_SCALER1_WTLIMIT))
#define  HPERF_NRT_DART_JPEG0_RTLIMIT	(0x0308)
#define rHPERF_NRT_DART_JPEG0_RTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_RTLIMIT))
#define  HPERF_NRT_DART_JPEG0_WTLIMIT	(0x030C)
#define rHPERF_NRT_DART_JPEG0_WTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_WTLIMIT))
#define  HPERF_NRT_DART_JPEG0_QOS	(0x0314)
#define rHPERF_NRT_DART_JPEG0_QOS	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_QOS))
#define  HPERF_NRT_DART_JPEG1_RTLIMIT	(0x0408)
#define rHPERF_NRT_DART_JPEG1_RTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_RTLIMIT))
#define  HPERF_NRT_DART_JPEG1_WTLIMIT	(0x040C)
#define rHPERF_NRT_DART_JPEG1_WTLIMIT	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_WTLIMIT))
#define  HPERF_NRT_DART_JPEG1_QOS	(0x0414)
#define rHPERF_NRT_DART_JPEG1_QOS	(*(volatile u_int32_t *)(NRT_DART_WIDGETS_BASE_ADDR + HPERF_NRT_DART_JPEG0_QOS))

#define  HPERF_NRT_DART_AR_CHAN_ARB_MI	(0x0408)
#define rHPERF_NRT_DART_AR_CHAN_ARB_MI	(*(volatile u_int32_t *)(NRT_DART_PL301_BASE_ADDR + HPERF_NRT_DART_AR_CHAN_ARB_MI0))
#define  HPERF_NRT_DART_AW_CHAN_ARB_MI	(0x040C)
#define rHPERF_NRT_DART_AW_CHAN_ARB_MI	(*(volatile u_int32_t *)(NRT_DART_PL301_BASE_ADDR + HPERF_NRT_DART_AW_CHAN_ARB_MI0))

#define  HPERF_NRT_TOP_TOP_RTLIMIT	(0x0008)
#define rHPERF_NRT_TOP_TOP_RTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_TOP_RTLIMIT))
#define  HPERF_NRT_TOP_TOP_WTLIMIT	(0x000C)
#define rHPERF_NRT_TOP_TOP_WTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_TOP_WTLIMIT))
#define  HPERF_NRT_TOP_VENC_RTLIMIT	(0x0108)
#define rHPERF_NRT_TOP_VENC_RTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VENC_RTLIMIT))
#define  HPERF_NRT_TOP_VENC_WTLIMIT	(0x010C)
#define rHPERF_NRT_TOP_VENC_WTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VENC_WTLIMIT))
#define  HPERF_NRT_TOP_VENC_WREQSP	(0x0110)
#define rHPERF_NRT_TOP_VENC_WREQSP	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VENC_WREQSP))
#define  HPERF_NRT_TOP_VDEC_RTLIMIT	(0x0208)
#define rHPERF_NRT_TOP_VDEC_RTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VDEC_RTLIMIT))
#define  HPERF_NRT_TOP_VDEC_WTLIMIT	(0x020C)
#define rHPERF_NRT_TOP_VDEC_WTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VDEC_WTLIMIT))
#define  HPERF_NRT_TOP_VDEC_WREQSP	(0x0210)
#define rHPERF_NRT_TOP_VDEC_WREQSP	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VDEC_WREQSP))
#define  HPERF_NRT_TOP_AUX_RTLIMIT	(0x0308)
#define rHPERF_NRT_TOP_AUX_RTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VDEC_RTLIMIT))
#define  HPERF_NRT_TOP_AUX_WTLIMIT	(0x030C)
#define rHPERF_NRT_TOP_AUX_WTLIMIT	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_VDEC_WTLIMIT))
#define  HPERF_NRT_TOP_AUX_WGATHER	(0x0310)
#define rHPERF_NRT_TOP_AUX_WGATHER	(*(volatile u_int32_t *)(NRT_TOP_WIDGETS_BASE_ADDR + HPERF_NRT_TOP_AUX_WGATHER))

#define  HPERF_NRT_TOP_AR_CHAN_ARB_MI	(0x0408)
#define rHPERF_NRT_TOP_AR_CHAN_ARB_MI	(*(volatile u_int32_t *)(NRT_TOP_PL301_BASE_ADDR + HPERF_NRT_TOP_AR_CHAN_ARB_MI0))
#define  HPERF_NRT_TOP_AW_CHAN_ARB_MI	(0x040C)
#define rHPERF_NRT_TOP_AW_CHAN_ARB_MI	(*(volatile u_int32_t *)(NRT_TOP_PL301_BASE_ADDR + HPERF_NRT_TOP_AW_CHAN_ARB_MI0))

#define  HPERF_RT_TOP_DISP0_RTLIMIT	(0x0004)
#define rHPERF_RT_TOP_DISP0_RTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_DISP0_RTLIMIT))
#define  HPERF_RT_TOP_DISP1_RTLIMIT	(0x000C)
#define rHPERF_RT_TOP_DISP1_RTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_DISP1_RTLIMIT))
#define  HPERF_RT_TOP_ISP_RTLIMIT	(0x0018)
#define rHPERF_RT_TOP_ISP_RTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_ISP_WTLIMIT))
#define  HPERF_RT_TOP_ISP_WTLIMIT	(0x001C)
#define rHPERF_RT_TOP_ISP_WTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_ISP_RTLIMIT))
#define  HPERF_RT_TOP_TOP_RTLIMIT	(0x0020)
#define rHPERF_RT_TOP_TOP_RTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_TOP_WTLIMIT))
#define  HPERF_RT_TOP_TOP_WTLIMIT	(0x0024)
#define rHPERF_RT_TOP_TOP_WTLIMIT	(*(volatile u_int32_t *)(RT_TOP_WIDGETS_BASE_ADDR + HPERF_RT_TOP_TOP_RTLIMIT))

#define  HPERF_RT_TOP_AR_CHAN_ARB_MI	(0x0408)
#define rHPERF_RT_TOP_AR_CHAN_ARB_MI	(*(volatile u_int32_t *)(RT_TOP_PL301_BASE_ADDR + HPERF_RT_TOP_AR_CHAN_ARB_MI0))
#define  HPERF_RT_TOP_AW_CHAN_ARB_MI	(0x040C)
#define rHPERF_RT_TOP_AW_CHAN_ARB_MI	(*(volatile u_int32_t *)(RT_TOP_PL301_BASE_ADDR + HPERF_RT_TOP_AW_CHAN_ARB_MI0))

#define	rSCC_CCXPWRCTRL			(*(volatile u_int32_t *)(SCC_BASE_ADDR + 0x2603C))


enum remap_select {
  REMAP_SRAM = 0,
  REMAP_SDRAM
};

extern void miu_select_remap(enum remap_select sel);
extern void miu_bypass_prep(int step);
extern void miu_update_device_tree(DTNode *pmgr_node);

extern u_int32_t miu_read_l2cadrmap(void);
extern void miu_write_l2cadrmap(u_int32_t value);

#endif /* ! __PLATFORM_SOC_MIU_H */
